
import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.Objects;

public class RepFile implements Serializable
{
    static final DecimalFormat df = new DecimalFormat("#.00");
    private String fileName;
    private String fileAuthor;
    private long size;
    private Date lastModification;
    private Date creation;
    
    public RepFile(String n)
    {
        fileName = n;
    }
    public RepFile(String n, String a, long s)
    {
        fileName = n;
        fileAuthor = a;
        creation = lastModification = new Date();
        size = s;
    }
    public String getName()
    {
        return fileName;
    }
    public String getAuthor()
    {
        return fileAuthor;
    }
    public long getLength()
    {
        return size;
    }
    public String getSize()
    {
        if(size/(1024*1024*1024) > 0)
        {
            return String.format("%.2f",(double)size/(1024*1024*1024)) + " GB";
        }
        if(size/(1024*1024) > 0)
        {
            return String.format("%.2f",(double)size/(1024*1024)) + " MB";
        }
        if(size/1024 > 0)
        {
            return String.format("%.2f",(double)size/1024) + " kB";
        }
        return String.format("%.2f",(double)size) + " B";
    }
    public String getCreationDate()
    {
        return (creation.getDate() < 10 ? "0"+creation.getDate() : creation.getDate()) + "/" + ((creation.getMonth()+1) < 10 ? "0"+(creation.getMonth()+1) : (creation.getMonth()+1)) + "/" + (creation.getYear()+1900) + " " + (creation.getHours() < 10 ? "0"+creation.getHours(): creation.getHours())+ ":" + (creation.getMinutes() < 10 ? "0"+creation.getMinutes(): creation.getMinutes()) + ":" + (creation.getSeconds() < 10 ? "0"+creation.getSeconds(): creation.getSeconds());
    }
    public String getLastModificationDate()
    {
        return (lastModification.getDate() < 10 ? "0"+lastModification.getDate() : lastModification.getDate()) + "/" + ((lastModification.getMonth()+1) < 10 ? "0"+(lastModification.getMonth()+1) : (lastModification.getMonth()+1)) + "/" + (lastModification.getYear()+1900) + " " + (lastModification.getHours() < 10 ? "0"+lastModification.getHours(): lastModification.getHours())+ ":" + (lastModification.getMinutes() < 10 ? "0"+lastModification.getMinutes(): lastModification.getMinutes()) + ":" + (lastModification.getSeconds() < 10 ? "0"+lastModification.getSeconds(): lastModification.getSeconds());
    }
    public void setSize(long s)
    {
        size = s;
    }
    public void setLastModified(long m)
    {
        lastModification = new Date(m);
    }
    @Override
    public boolean equals(Object obj) 
    {
        if (obj != null && obj instanceof RepFile)
        {
            return this.fileName.equals(((RepFile)obj).fileName);
        }
        return false;
    }
    @Override
    public int hashCode() 
    {
        int hash = 3;
        hash = 79 * hash + Objects.hashCode(this.fileName);
        return hash;
    }
}